//package com.xiangxiangjd.aircraftanalysis.config.shiro;
//
//import com.alibaba.fastjson.JSONObject;
//import com.xiangxiangjd.aircraftanalysis.config.token.JwtUtils;
//import io.jsonwebtoken.Claims;
//import org.apache.shiro.web.servlet.AdviceFilter;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Configuration;
//
//import javax.servlet.ServletRequest;
//import javax.servlet.ServletResponse;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import javax.servlet.http.HttpSession;
//import java.io.PrintWriter;
//import java.util.ArrayList;
//import java.util.List;
//
//
//@Configuration
//public class ShiroInterceptor extends AdviceFilter {
//    private static final List<String> USER_LOGIN = new ArrayList();
//
//    static {
//        USER_LOGIN.add("/aircraftanalysis/user/admin/login");
//
//    }
//
//
//    @Autowired
//    private JwtUtils jwtUtils;
//
//
//    @Override
//    protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {
//        HttpServletRequest request1 = (HttpServletRequest) request;
//
//        String token = request1.getHeader("token");
//
//        System.out.println("本次访问的路径"+request1.getRequestURI());
//
//        if(USER_LOGIN.contains(request1.getRequestURI())) return true;
//
//
//        System.out.println("token 是否存在:"+token);
//        if (token == null) {
//            System.out.println("token不存在");
//
//            response.setCharacterEncoding("UTF-8");
//            response.setContentType("application/json; charset=utf-8");
//            JSONObject res = new JSONObject();
//            res.put("success", "false");
//            res.put("code", "501");
//            res.put("msg", "token 不存在!");
//            response.getWriter().append(res.toString());
//            return false;
//        }
//
//
//        //解析token
//        Claims claims = jwtUtils.parseJwt(token);
//       if (claims==null){
//           response.setCharacterEncoding("UTF-8");
//           response.setContentType("application/json; charset=utf-8");
//           JSONObject res = new JSONObject();
//           res.put("success", "false");
//           res.put("code", "501");
//           res.put("msg", "登录过期 请重新登录!");
//           response.getWriter().append(res.toString());
//        return false;
//       }
//
//
//        System.out.println("验证token 成功"+claims);
//
//        return true;
//    }
//
//
//    @Override
//    public void afterCompletion(ServletRequest request, ServletResponse response, Exception exception) throws Exception {
//
////        String localAddr = request.getLocalAddr();
////        System.out.println("localAddr:"+localAddr);
////        int localPort = request.getLocalPort();
////        System.out.println("localPort:"+localPort);
////
////
////                HttpServletRequest request1 =(HttpServletRequest)request;
////
////        String requestURI = request1.getRequestURI();
////
////        System.out.println("requestURI:"+requestURI);
////        StringBuffer stringBuffer=request1.getRequestURL();
////
////        System.out.println("stringBuffer:"+stringBuffer);
////        String queryString = request1.getQueryString();
////
////        System.out.println("queryString:"+queryString);
////
////
//
//
////        String contextPath = ((HttpServletRequest) request).getContextPath();
//
////        System.out.println("contextPath:"+contextPath);
//
//    }
//}
